package com.project.finance.productdetail.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.finance.common.mapper.TbProductDetailMapper;
import com.project.finance.common.po.TbProductDetail;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.productdetail.service.ProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
@Service
public class ProductDetailServiceImpl implements ProductDetailService {
    @Autowired
    private TbProductDetailMapper tbProductDetailMapper;
    @Override
    public List<TbProductDetail> listdetail() {
        return tbProductDetailMapper.listdetail();
    }

    @Override
    public int delete(int productdetailid) {
        return tbProductDetailMapper.deleteByPrimaryKey(productdetailid);
    }

    @Override
    public ResultMsg listProductDetailByPage(int pageSize, int pageNum) {
        ResultMsg resultMsg = new ResultMsg();

        PageHelper.startPage(pageNum,pageSize);

        List<TbProductDetail> tbProductDetails = tbProductDetailMapper.listdetail();

        //获取结果集的分页信息
        PageInfo pageInfo=new PageInfo(tbProductDetails);
        //获取总记录数
        long total = pageInfo.getTotal();
        resultMsg.setTatol(total);
        resultMsg.setData(tbProductDetails);
        return resultMsg;
    }

    //根据理财产品名称来查询一个产品详情信息
    @Override
    public List<TbProductDetail> getProoductDetail(int productderailid) {
        Example example = new Example(TbProductDetail.class);
        Example.Criteria criteria=example.createCriteria();
        criteria.andLike("productDetailId","%"+productderailid+"%");
        List<TbProductDetail> tbProductDetails = tbProductDetailMapper.selectByExample(example);
        return tbProductDetails;
    }
}
